﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Assets
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CurrentMenuIDContent" runat="server" >assetMenu</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <link rel="stylesheet" type="text/css" href="../../Content/jquery-ui-1.8.16.custom.css" />
    <script type="text/javascript" src="../../Scripts/site.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.pager.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery-ui-1.8.16.custom.min.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Asset Management</h2>
    <table>
        <tr>
            <td width="130px">
                Filter By Asset Type:
            </td>
            <td align="left">
                <%= Html.DropDownList("AssetType", "---All---")%>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td width="130px">
                Filter By Site:
            </td>
            <td>
                <%= Html.DropDownList("Site", "---All---")%>
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td width="130px">
                Filter By Department:
            </td>
            <td>
                <div id="departmentContainer"><%= Html.DropDownList("Department", "---All---")%></div>
            </td>
            <td>
                <form method="get" action='<%= Html.AttributeEncode(Url.Action("Create")) %>'>
                <input type="submit" class="button right" value="Create Asset" />
                </form>
            </td>
        </tr>
        <tr>
            <td id="assetListContent" colspan="3">
                <% Html.RenderPartial("~/Views/Asset/Controls/AssetGrid.ascx")%>
            </td>
        </tr>
    </table>
    <% Html.RenderPartial("~/Views/History/Controls/History.ascx")%>
    <%  Html.RenderPartial("~/Views/Asset/Controls/StatusDialog.ascx")%>
        <script type="text/javascript">

            $(document).ready(function () {
                $("#assetTable")
            .tablesorter({ widthFixed: true, widgets: ['zebra'] })
            .tablesorterPager({ container: $("#pager"), positionFixed: false });

                initSelects();

                $("select#Site").change(function () {
                    loadDepartmentList();
                });

            });

            statusDialog.OnSuccess = function (id, desc) {
                $("#assetStatusDesc_" + id).text(desc);
                $("#asset_" + id + " td").effect('highlight', {}, 2000);
            }

            function initSelects() {
                $("select").change(function () {
                    setFilter();
                });
            }

            function setFilter() {
                var assetTypeID = $("#AssetType").val();
                var siteID = $("#Site").val();
                var depID = $("#Department").val();
                showLoading("assetListContent", true);
                jQuery.ajax({
                    type: 'POST',
                    data: { assetTypeID: assetTypeID, siteID: siteID, depID: depID },
                    url: '<%= Html.AttributeEncode(Url.Action("FilterAsset")) %>',
                    success: function (result) {
                        $('#assetListContent').html(result);
                        hideLoading("assetListContent");
                    }
                });
            }

            function loadDepartmentList() {
                var siteID = $("#Site").val();
                jQuery.ajax({
                    type: 'POST',
                    data: { siteID: siteID },
                    url: '<%= Html.AttributeEncode(Url.Action("GetDepartmentDDBySiteID")) %>',
                    success: function (result) {
                        $('#departmentContainer').html(result);
                        $("select#Site").change(function () {
                            setFilter();
                        });
                    }
                });
            }

    </script>
</asp:Content>
